package main

import (
	"gitee.com/injoyai/goutil/net/conn/v2"
	"gitee.com/injoyai/goutil/net/tcp/V2"
	"gitee.com/injoyai/goutil/oss/io"
	"log"
	"time"
)

func main() {
	s, _ := tcp.NewServer(10086)
	s.Debug()
	s.SetPrintWithASCII()
	s.SetReadFunc(io.ReadWithAll)
	//s.SetSendFunc(nil)
	//s.SetReadFunc(io.ReadWithStartEnd([]byte{2, 2}, []byte{3, 3}))
	s.SetTimeout(time.Second * 180)
	s.SetDealFunc(func(m *conn.Message) {

		//time.Sleep(time.Second * 10)
		//msg := new(callback.Msg)
		//msg.SetErr(json.Unmarshal(m.Bytes(), msg))
		//msg.SetMsg("成功")
		//time.Sleep(time.Second)
		//s.SetConnKey(m.Conn(), m.String())
		//m.Conn().SendBytes([]byte("succ"))
		m.Client().Write([]byte{0x68, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x68, 0x91, 0x08, 0x33, 0x33, 0x33, 0x33, 0x34, 0x33, 0x33, 0x33, 0x7e, 0x16})

		//m.Conn().SendBytes([]byte{0x68, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x68, 0x91, 0x08, 0x33, 0x33, 0x33, 0x33, 0x34, 0x33, 0x33, 0x33, 0x7e, 0x16})

	})
	go func() {
		for {
			time.Sleep(time.Second * 5)
			//logs.Debug(s.GetConnAll())
			for _, c := range s.GetConnAll() {
				//c.Close()
				_ = c
				//c.Send("666")
				//logs.PrintErr(c.Send("ping"))
			}
		}
	}()
	log.Println(s.Run())
}
